// 用户接口
import http from '../service/http';
import mockHttp from '../service/mockAxios';

// 获取用户列表
export function getUserList() {
  return http({
    url: '/users/list',
    method: 'get',
    headers: {
      authorization: sessionStorage.getItem('token'),
    },
  });
}

// 用户登录
export function login(data) {
  return http({
    url: '/users/login',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data,
  });
}

// 获取详细信息
export function getuserinfo(id) {
  return http({
    url: '/users/info',
    method: 'get',
    params: {
      id: id,
    },
    headers: {
      authorization: sessionStorage.getItem('token'),
    },
  });
}

// 修改登录用户个人资料
// export function editUserInfo(id,data) {
//   return http({
//     url: '/users/update',
//     method: 'post',
//     headers: {
//       authorization: sessionStorage.getItem('token'),
//     },
//     params: {
//       id: id,
//     },
//     data,
//   });
// }

// 注销登录
export function logout(id) {
  return http({
    url: '/users/logout',
    method: 'get',
    params: {
      id: id,
    },
  });
}

// 修改密码
export function changepass(id,data) {
  return http({
    url: '/users/rpwd',
    method: 'post',
    headers: {
      authorization: sessionStorage.getItem('token'),
    },
    params: {
      id: id,
      data,
    },
  });
}

// 注册新用户
export function registerUser(data) {
  return http({
    url: '/users/register',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data,
  });
}

// 获取用户列表
export function getList() {
  return mockHttp.get('/data');
}

// 修改用户资料
export function edit(id, data) {
  return mockHttp.patch(`/data/${id}`, data);
}

// 添加新用户
export function adduser(data) {
  return mockHttp.post('/data', data);
}

// 删除用户
export function deletuser(id) {
  return mockHttp.delete(`/data/${id}`);
}

// -----------------------------------------------角色相关-----------------------------------------------
// 获取角色列表
export function getroles() {
  return mockHttp.get('/role');
}

// 修改角色资料
export function roleedit(id, data) {
  return mockHttp.patch(`/role/${id}`, data);
}

// 添加新角色
export function addrole(data) {
  return mockHttp.post('/role', data);
}

// 删除角色
export function deletrole(id) {
  return mockHttp.delete(`/role/${id}`);
}

// -----------------------------------------------部门相关-----------------------------------------------
// 获取部门列表
export function getdeps() {
  return mockHttp.get('/department');
}

// 修改部门资料
export function depsedit(id, data) {
  return mockHttp.patch(`/department/${id}`, data);
}

// 添加新部门
export function adddep(data) {
  return mockHttp.post('/department', data);
}

// 删除部门
export function deletdep(id) {
  return mockHttp.delete(`/department/${id}`);
}
